package com.umfwechat.util;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.umpay.operation.common.ReqMessage;
import com.umpay.operation.util.DateTimesUtil;

public class PmUtils {
	private static Logger logger = LoggerFactory.getLogger(PmUtils.class);
	
	/**
	 * 生成rpId
	 * 
	 * @return
	 */
	public static String randomRpId() {
		DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String formatDate = format.format(new Date());
		return new StringBuffer().append("PM").append(formatDate).toString();
	}
	
	public static String randomRpId14() {
		DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String formatDate = format.format(new Date());
		return formatDate.toString();
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static ReqMessage getReqMessage(Map data) throws Exception{
		Date date = new Date();
		ReqMessage req = new ReqMessage();
		req.setRpid(randomRpId());
		req.setReqDate(DateTimesUtil.formatDate(date, DateTimesUtil.formatDay8Str));
		req.setReqTime(DateTimesUtil.formatDate(date, DateTimesUtil.formatTime6Str));
		req.put(data);
		return req;
	}
	public static ReqMessage getReqMessage() throws Exception{
		Date date = new Date();
		ReqMessage req = new ReqMessage();
		req.setRpid(randomRpId());
		req.setReqDate(DateTimesUtil.formatDate(date, DateTimesUtil.formatDay8Str));
		req.setReqTime(DateTimesUtil.formatDate(date, DateTimesUtil.formatTime6Str));
		return req;
	}
	//获取请求报文头
	public static void getReqMessageHeader(ReqMessage req) throws Exception{
		Date date = new Date();
		req.setRpid(randomRpId());
		req.setReqDate(DateTimesUtil.formatDate(date, DateTimesUtil.formatDay8Str));
		req.setReqTime(DateTimesUtil.formatDate(date, DateTimesUtil.formatTime6Str));
	}
}
